<%@ page import="ex01.Person" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %><%--
  Created by IntelliJ IDEA.
  User: wg
  Date: 2017/10/16
  Time: 15:52
  Description: 
--%>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>JSTL</title>
</head>
<body>
    <%
        int x = 3, y = 4;
        // el表达式快速的获取各个隐式变量中的数据
        request.setAttribute("x", 4);
        request.setAttribute("y", 2);

        // 数组
        request.setAttribute("array", new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9});

        // 对象
        Person[] personArray = new Person[] {
                new Person(11, "wch", false),
                new Person(12, "wch", true)
        };

        request.setAttribute("p1", personArray);

        // List
        request.setAttribute("p2", Arrays.asList(personArray));

        // 添加Map
        Map<String, Person> map = new HashMap<>();
        map.put("p1", personArray[0]);
        map.put("p2", personArray[1]);
        request.setAttribute("p3", map);
    %>
    <c:if test="${requestScope.x > requestScope.y}">
        x > y
    </c:if>

    ${x};

    <c:forEach items="${requestScope.array}" var="item">
        ${item}
    </c:forEach>
    <br>
    <br>

    <table border="1">
        <tr>
            <th>名字</th>
            <th>年龄</th>
            <th>性别</th>
        </tr>

        <c:forEach items="${requestScope.p1}" var="item">
        <tr>
            <td>${item.name}</td>
            <td>${item.age}</td>
            <td>${item.man}</td>
        </tr>
        </c:forEach>

        <c:forEach items="${requestScope.p2}" var="item">
            <tr>
                <td>${item.name}</td>
                <td>${item.age}</td>
                <td>${item.man}</td>
            </tr>
        </c:forEach>

        <c:forEach items="${requestScope.p3}" var="item">
            <tr>
                <td>${item.value.name}</td>
                <td>${item.value.age}</td>
                <td>${item.value.man}</td>
            </tr>
        </c:forEach>
    </table>
</body>
</html>
